package com.redside.webapp.util;

import java.beans.PropertyEditorSupport;

import com.redside.Constants;
import com.redside.model.lookup.CountyLkp;
import com.redside.service.OptionsBeanLookupManager;

public class CustomCountyEditor  extends PropertyEditorSupport {
 
    private final OptionsBeanLookupManager optionsBeanManager;
 
    public CustomCountyEditor(OptionsBeanLookupManager optionsBeanLookupDao) {
        this.optionsBeanManager = optionsBeanLookupDao;
    }
 
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
    	//TODO fix to get value from text field
    	System.out.println("Here is the text:Here is the text:Here is the text:Here is the text:");
    	System.out.println("Here is the text: "+text);
    	CountyLkp lkp = new CountyLkp(optionsBeanManager.findById(Constants.COUNTY_BEAN, "051"));
    	//CountyLkp lkp = new CountyLkp("051","Multnomah");
        setValue(lkp);
    }
 
    @Override
    public String getAsText() {
        CountyLkp s = (CountyLkp) getValue();
        if (s == null) {
            return null;
        } else {
            return s.getCountyId();
        }
    }
}